﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SQLDataUploadHelper.commons.controls
{
    /// <summary>
    /// ServerInfoControl.xaml 的交互逻辑
    /// </summary>
    public partial class ServerInfoControl : UserControl
    {
        public delegate void ClickEvent(object sender, bool IsDelete = false);
        public event ClickEvent Click;

        public ServerInfoControl()
        {
            InitializeComponent();
        }

        public long Id { get; set; }

        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set
            {
                SetValue(UrlProperty, value);
                urlTextBlock.Text = value;
            }
        }
        public static readonly DependencyProperty UrlProperty =
            DependencyProperty.Register("Url", typeof(string), typeof(ServerInfoControl), new PropertyMetadata(default(string)));

        public string UserName
        {
            get { return (string)GetValue(UserNameProperty); }
            set
            {
                SetValue(UserNameProperty, value);
                userNameTextBlock.Text = value;
            }
        }
        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(string), typeof(ServerInfoControl), new PropertyMetadata(default(string)));

        public string Password
        {
            get { return (string)GetValue(PasswordProperty); }
            set
            {
                SetValue(PasswordProperty, value);
                passwordTextBlock.Text = value;
            }
        }
        public static readonly DependencyProperty PasswordProperty =
            DependencyProperty.Register("Password", typeof(string), typeof(ServerInfoControl), new PropertyMetadata(default(string)));

        /// <summary>
        /// 删除点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PathButton_Click(object sender, RoutedEventArgs e)
        {
            if (Click != null)
            {
                Click(this, true);
            }
        }

        private void Border_MouseEnter(object sender, MouseEventArgs e)
        {
            border.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f5f5f5"));
        }

        private void Border_MouseLeave(object sender, MouseEventArgs e)
        {
            border.Background = Brushes.Transparent;
        }

        /// <summary>
        /// 选中点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Click != null)
            {
                Click(this, false);
            }
        }
    }
}
